﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace JenkinsController.Tests.Framework
{
    using JenkinsController.Framework;
    using Ploeh.AutoFixture;

    [TestClass]
    public class ObjectsEqualsConverterTests
    {
        private readonly Fixture defaultFixture = new Fixture();
        private ObjectsEqualsConverter converter;

        [TestInitialize]
        public void InitContext()
        {
            converter = new ObjectsEqualsConverter();
        }

        [TestMethod]
        public void Invoke_Convert_OnNullValue_ShouldReturnFalse()
        {
            Assert.IsFalse((bool)converter.Convert(null, null, null,null));
        }

        [TestMethod]
        public void Invoke_Convert_OnOneElementArrayValue_ShouldReturnFalse()
        {
            Assert.IsFalse((bool)converter.Convert(new[]{defaultFixture.Create<object>()}, null, null, null));
        }

        [TestMethod]
        public void Invoke_Convert_OnNonEqualsValues_ShouldReturnFalse()
        {
            Assert.IsFalse((bool)converter.Convert(defaultFixture.Create<object[]>(), null, null, null));
        }

        [TestMethod]
        public void Invoke_Convert_OnEqualsValues_ShouldReturnTrue()
        {
            var elt = new object();
            var array = new[] { elt, elt, elt };
            Assert.IsTrue((bool)converter.Convert(array, null, null, null));
        }

        [TestMethod]
        [ExpectedException(typeof(NotImplementedException))]
        public void Invoke_ConvertBack_ShouldThrowException()
        {
            converter.ConvertBack(null, null, null, null);
        }
    }
}
